﻿<template>
  <a-modal
    title="新增库区信息"
    :width="900"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    @cancel="handleCancel">
    <a-spin :spinning="confirmLoading">
		<a-form :form="form">
        <a-form-item label="名称" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入名称" v-decorator="['areaName', {rules: [{ required: true, message: '请输入名称！' }]}]" />
        </a-form-item>
        <a-form-item label="描述" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入描述" v-decorator="['areaDesc', {rules: [{ required: true, message: '请输入描述！' }]}]" />
        </a-form-item>
        <!-- <a-form-item label="状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-select style="width: 100%" placeholder="请选择状态" v-decorator="['areaStatus', {rules: [{ required: true, message: '请选择状态！' }]}]">
            <a-select-option v-for="(item,index) in areaStatusData" :key="index" :value="item.code">{{ item.name }}</a-select-option>
          </a-select>
        </a-form-item> -->
        <a-form-item label="分类" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-select style="width: 100%" placeholder="请选择分类" v-decorator="['areaType', {rules: [{ required: true, message: '请选择分类！' }]}]">
            <a-select-option v-for="(item,index) in areaTypeData" :key="index" :value="item.code">{{ item.name }}</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="所属车间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-select style="width: 100%" placeholder="请选择所属车间" v-decorator="['workShopType', {rules: [{ required: true, message: '请选择所属车间！' }]}]">
            <a-select-option v-for="(item,index) in workShopTypeData" :key="index" :value="item.code">{{ item.name }}</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="是否为钢平台" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-switch v-decorator="['isSteel', { valuePropName: 'checked' }]" />
        </a-form-item>
        <!-- <a-form-item label="签核状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-select style="width: 100%" placeholder="请选择签核状态" v-decorator="['issueState', {rules: [{ required: true, message: '请选择签核状态！' }]}]">
            <a-select-option v-for="(item,index) in issueStateData" :key="index" :value="item.code">{{ item.name }}</a-select-option>
          </a-select>
        </a-form-item> -->
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import {
    WmsAreaAdd
  } from '@/api/modular/main/WmsAreaManage'
  export default {
    data () {
      return {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 15 }
        },
        areaStatusData: [],
        areaTypeData: [],
        workShopTypeData: [],
        //issueStateData: [],
        visible: false,
        confirmLoading: false,
        form: this.$form.createForm(this)
      }
    },
    methods: {
      // 初始化方法
      add (record) {
        this.visible = true
        this.$nextTick(() => {

        });
        const areaStatusOption = this.$options
        this.areaStatusData = areaStatusOption.filters['dictData']('common_status')
        const areaTypeOption = this.$options
        this.areaTypeData = areaTypeOption.filters['dictData']('area_type')
        const workShopTypeOption = this.$options
        this.workShopTypeData = workShopTypeOption.filters['dictData']('les_workshop_type')
        // const issueStateOption = this.$options
        // this.issueStateData = issueStateOption.filters['dictData']('issue_state')
      },
      /**
       * 提交表单
       */
      handleSubmit () {
        const { form: { validateFields } } = this
        this.confirmLoading = true
        validateFields((errors, values) => {
          if (!errors) {
            for (const key in values) {
              if (typeof (values[key]) === 'object') {
                values[key] = JSON.stringify(values[key])
              }
            }
            WmsAreaAdd(values).then((res) => {
              if (res.success) {
                this.$message.success('新增成功')
                this.confirmLoading = false
                this.$emit('ok', values)
                this.handleCancel()
              } else {
                this.$message.error('新增失败：' + JSON.stringify(res.message))
              }
            }).finally((res) => {
              this.confirmLoading = false
            })
          } else {
            this.confirmLoading = false
          }
        })
      },
      handleCancel () {
        this.form.resetFields()
        this.visible = false
      }
    }
  }
</script>
